package com.uenpay.im.invokeitems.chat;

import com.qiyunxin.android.http.utils.Utils;
import com.qyx.android.utilities.DateUtils;
import com.uenpay.im.IMApplication;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class AutoJoinGroupInvokeItem extends BaseHttpInvokeItem {
	public class AutoJoinGroupInvokeItemResult extends HttpInvokeResult {
		public int status;
		public String msg;
	}

	public AutoJoinGroupInvokeItemResult getOutput() {
		return (AutoJoinGroupInvokeItemResult) GetResultObject();
	}

	public AutoJoinGroupInvokeItem(String chatid) {
		//http://api.qiyunxin.com/Chat/Chat/autoJoin?chatid=&time=&sign=&regtype=1|2
		String time = DateUtils.getCurrentSeconds() + "";
		String sign = Utils.md5(Utils.md5(IMApplication.getUserMobilePhone() + "_" + time));
		String url = APIConfiguration.getBaseUrl() + "Chat/Chat/autoJoin?chatid="+chatid+"&time="+time+"&sign="+sign+"&regtype=1&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		AutoJoinGroupInvokeItemResult result = new AutoJoinGroupInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}

}
